<template>
  <div class="app-container">
    <div style="width: 100%; margin-bottom: 10px">
      <el-button type="primary" size="mini" @click="addCommand">指派维保人员</el-button>
    </div>

    <el-table v-loading="loading" :data="detailList">
      <el-table-column label="编号" width="50" type="index" align="center" fixed="left"
                       :index="index=>index+1"/>
      <el-table-column label="申报单号" prop="reportId" width="120" align="center" fixed="left"/>
      <el-table-column label="住户编号" prop="customerId" width="120" align="center"/>
      <el-table-column label="具体地址" prop="location" width="120" align="center"/>
      <el-table-column label="申报内容" prop="content" width="120" align="center"/>
      <el-table-column label="预约时间" align="center" prop="createTime" width="160">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.bookTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="指派状态" prop="status" width="120" align="center">
        <template #default="scope">
          <span v-show="!scope.row.editFlag">{{scope.row.status}}</span>
          <el-select   v-show="scope.row.editFlag"  v-model="scope.row.status" placeholder="请选择指派状态" clearable :style="{width: '100%'}">
            <el-option label="未同意" value="未同意"></el-option>
            <el-option label="已同意" value="已同意"></el-option>
            <el-option label="已完成" value="已完成"></el-option>
          </el-select>
        </template>
      </el-table-column>
      <el-table-column prop="keepName" label="维保人员" align="center" width="150">
        <template #default="scope">
          <span v-show="!scope.row.editFlag">{{scope.row.keepName}}</span>
          <el-select   v-show="scope.row.editFlag"  v-model="scope.row.keeperId" placeholder="请选择人员名称" clearable :style="{width: '100%'}">
            <el-option v-for="(item, index) in garbageTypeOptions" :key="index" :label="item.label"
                       :value="item.value" :disabled="item.disabled"></el-option>
          </el-select>
        </template>
      </el-table-column>
      <el-table-column label="联系电话" prop="keepPhone" width="120" align="center"/>
      <el-table-column label="创建人" prop="createBy" width="120" align="center"/>
      <el-table-column label="修改人" prop="updateBy" width="120" align="center"/>
      <el-table-column label="创建时间" align="center" prop="createTime" width="160">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="修改时间" align="center" prop="createTime" width="160">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.updateTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" fixed="right" width="140">-->
                <template #default="scope">
                  <div style="">
                    <el-button size="small"
                               type="text"
                               icon="CircleCheck"
                               v-show="scope.row.editFlag"
                               @click="submit(scope.row, $index)">保存
                    </el-button>
                    <el-button size="small"
                               type="text"
                               icon="CircleClose"
                               v-show="scope.row.editFlag"
                               @click="cancel(scope.row, $index)">取消
                    </el-button>
                    <el-button size="small"
                               icon="Edit"
                               type="text"
                               v-show="!scope.row.editFlag"
                               @click="edit(scope.row, $indx)"> 编辑
                    </el-button>
                    <el-button size="small"
                               icon="Delete"
                               type="text"
                               v-show="!scope.row.editFlag"
                               @click="del(scope.row, $index)">删除
                    </el-button>
                  </div>
                </template>
              </el-table-column>
    </el-table>
  </div>
</template>


<script>
  import { listAll, get, del, add, update,listAllGarbageType } from "@/api/device/deatail";

export default {
  name: "BaseDetail",
  dicts: ['sys_normal_disable'],
  data() {
    return {
      baseUrl: process.env.VUE_APP_BASE_API,
      id: undefined,
      // 遮罩层
      loading: true,
      // 菜品明细表格数据
      detailList: [],
      garbageTypeOptions: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false
    };
  },
  created() {
    this.id = this.$route.params && this.$route.params.id;
    this.getList();
    listAllGarbageType().then(res => {
      this.garbageTypeOptions = [];
      for (var i = 0; i < res.rows.length; i++) {
        this.garbageTypeOptions.push({
          label: res.rows[i].name,
          value: res.rows[i].id
        });
      }
    })
  },
  methods: {
    /** 查询列表 */
    getList() {
      this.loading = true;
      listAll({
        reportId: this.id,
      }).then(response => {
          this.detailList = response.rows;
          this.loading = false;
        }
      );
    },
    addCommand: function() {
      var detail = {
        reportId: this.id,
        status: "未同意"
      }
      add(detail).then(res => {
        this.getList();
      })
    },
    submit: function(row, index) {
      let updateData = {
        id: row.id,
        keeperId: row.keeperId,
        status: row.status
      }
      update(updateData).then(res => {
        this.$modal.msgSuccess("更新成功");
        row.editFlag = false;
        this.getList();
      })
    },
    cancel: function(row, index) {
      row.editFlag = false;
      this.getList();
    },
    edit: function(row, index) {
      row.editFlag = true;
      this.$set(this.detailList, index, row);
    },
    del: function(row, index) {
      del(row.id).then(response => {
        this.$modal.msgSuccess("删除成功");
        this.getList();
      });
    }
  }
};
</script>
